package com.example.tools.BitMap;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.io.File;

/**
 * Created by Administrator on 2016/10/18.
 */

public class GlideUtils {

    /**
     * 从网络加载图片到Activity
     * @param activity
     * @param url
     * @param imageView
     */
    public static void loadImage(Activity activity, String url , ImageView imageView){
        Glide.with(activity).load(url).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity, String url , ImageView imageView,int wieth,int hight){
        Glide.with(activity).load(url).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity, File file , ImageView imageView){
        Glide.with(activity).load(file).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity, File file , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(file).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity,Integer resourceId , ImageView imageView){
        Glide.with(activity).load(resourceId).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity,Integer resourceId , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(resourceId).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity, Uri uri , ImageView imageView){
        Glide.with(activity).load(uri).into(imageView);
    }

    public static void loadImageOnActivity(Activity activity, Uri uri , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(uri).override(wieth, hight).into(imageView);
    }



    /**
     * 从网络加载 Gif 加入缓存策略
     * @param activity
     * @param url
     * @param imageView
     */
    public static void loadGifOnActivity(Activity activity, String url , ImageView imageView){
        Glide.with(activity).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    public static void loadGifOnActivity(Activity activity, Integer resourceId , ImageView imageView){
        Glide.with(activity).load(resourceId).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }



    public static void loadGifOnActivity(Activity activity, Uri uri , ImageView imageView){
        Glide.with(activity).load(uri).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    public static void loadGifOnActivity(Activity activity, File file  , ImageView imageView){
        Glide.with(activity).load(file).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    /**
     * 从网络加载图片到Activity
     * @param activity
     * @param url
     * @param imageView
     */
    public static void loadImage(FragmentActivity activity, String url , ImageView imageView){
        Glide.with(activity).load(url).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity, String url , ImageView imageView,int wieth,int hight){
        Glide.with(activity).load(url).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity, File file , ImageView imageView){
        Glide.with(activity).load(file).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity, File file , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(file).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity,Integer resourceId , ImageView imageView){
        Glide.with(activity).load(resourceId).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity,Integer resourceId , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(resourceId).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity, Uri uri , ImageView imageView){
        Glide.with(activity).load(uri).into(imageView);
    }

    public static void loadImageOnActivity(FragmentActivity activity, Uri uri , ImageView imageView, int wieth, int hight){
        Glide.with(activity).load(uri).override(wieth, hight).into(imageView);
    }



    /**
     * 从网络加载 Gif 加入缓存策略
     * @param activity
     * @param url
     * @param imageView
     */
    public static void loadGifOnActivity(FragmentActivity activity, String url , ImageView imageView){
        Glide.with(activity).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    public static void loadGifOnActivity(FragmentActivity activity, Integer resourceId , ImageView imageView){
        Glide.with(activity).load(resourceId).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }



    public static void loadGifOnActivity(FragmentActivity activity, Uri uri , ImageView imageView){
        Glide.with(activity).load(uri).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    public static void loadGifOnActivity(FragmentActivity activity, File file  , ImageView imageView){
        Glide.with(activity).load(file).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    /**
     * 从网络加载图片  到Fragment
     * @param fragment
     * @param url
     * @param imageView
     */
    public static void loadImageOnFragment(Fragment fragment , String url , ImageView imageView){
        Glide.with(fragment).load(url).into(imageView);
    }

    public static void loadImageOnFragment(Fragment fragment , String url , ImageView imageView,int wieth,int hight){
        Glide.with(fragment).load(url).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnFragment(Fragment fragment, File file , ImageView imageView){
        Glide.with(fragment).load(file).into(imageView);
    }

    public static void loadImageOnFragment(Fragment fragment, File file , ImageView imageView, int wieth, int hight){
        Glide.with(fragment).load(file).override(wieth, hight).into(imageView);
    }

    public static void loadImageOnFragment(Fragment fragment,Integer resourceId , ImageView imageView){
        Glide.with(fragment).load(resourceId).into(imageView);
    }

    public static void loadImageOnFragment(Fragment fragment,Integer resourceId , ImageView imageView, int wieth, int hight){
        Glide.with(fragment).load(resourceId).override(wieth, hight).into(imageView);
    }


    /**
     * 从网络加载 Gif 加入缓存策略
     * @param fragment
     * @param url
     * @param imageView
     */
    public static void loadGifOnFragment(Fragment fragment, String url , ImageView imageView){
        Glide.with(fragment).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnFragment(Fragment fragment, Integer resourceId , ImageView imageView){
        Glide.with(fragment).load(resourceId).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnFragmentS(Fragment fragment, Uri uri , ImageView imageView){
        Glide.with(fragment).load(uri).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnFragment(Fragment fragment, File file  , ImageView imageView){
        Glide.with(fragment).load(file).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    /**
     * 从网络加载图片 Context 通用
     * @param context
     * @param url
     * @param imageView
     *
     */
    public static void loadImageOnContext(Context context , String url , ImageView imageView){
        Glide.with(context).load(url).into(imageView);
    }

    public static void loadImageOnContext(Context context , String url , ImageView imageView,int wieth,int hight){
        Glide.with(context).load(url).override(wieth, hight).into(imageView);
    }

    public static void loadGifOnContext(Context context, String url , ImageView imageView){
        Glide.with(context).load(url).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnContext(Context context, Integer resourceId , ImageView imageView){
        Glide.with(context).load(resourceId).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnContext(Context context, Uri uri , ImageView imageView){
        Glide.with(context).load(uri).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }

    public static void loadGifOnContext(Context context, File file ,ImageView imageView){
        Glide.with(context).load(file).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
    }


    public static void OnResume(Activity activity){
        Glide.with(activity).resumeRequests();
    }

    public static void OnPause(Activity activity){
        Glide.with(activity).pauseRequests();
    }
}
